package com.alks.function.mapper.chengKong;

import com.alks.entity.data.entity.*;
import com.alks.function.data.dto.chengKong.assort.SdStyleColorDto;
import com.alks.function.data.dto.chengKong.assort.SdStyleDto;
import com.alks.function.data.dto.chengKong.assort.SdStyleTypeDto;
import com.alks.function.data.dto.chengKong.assort.YfStyleSizeDto;
import com.alks.function.data.request.chengKong.StyleNoRequest;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;


public interface LargeCargoTypeMapper {

    /**
     * 查询型体是否存在
     * @param styleNo
     * @param companyId
     * @return
     */
    @Select("select STYLE_NO from SD_STYLE where STYLE_NO=#{styleNo} and COMPANY_ID=#{companyId}")
    String getStyleNo(@Param("styleNo") String styleNo, @Param("companyId") String companyId);

     /**
      * 查询型体基本资料
      * @param styleNo
      * @return
      */
     @Select("select * from YF_STYLE where STYLE_NO=#{styleNo}")
     YfStyle getStyleBasicDetail(@Param("styleNo") String styleNo);

     /**
      * 查询制具资料
      * @param styleNo
      * @return
      */
     @Select("select * from YF_STYLE_TYPE where STYLE_NO=#{styleNo}")
     YfStyleType getStyleTypeDetail(@Param("styleNo") String styleNo);

     /**
      * 新增
      * @param sdStyle
      */
     @Insert("insert into SD_STYLE(COMPANY_ID,STYLE_NO,STYLE_ABBR,STYLE_NAME,CUSTOM_NO,CUST_NO,CUST_BRAND,LAST_MOLD,CUT_TOOL,SOLE_PART,BASE_SIZE,SAMPLE_DESIGNER," +
             "PROD_REMARK1,PROD_REMARK2,PROD_REMARK3,PROD_REMARK4,PROD_REMARK5,SYS_USER,SYS_DATE,CUSTOM_NAME,CFM_FLAG,CFM_USER,CFM_DATE,SIZE_TYPE,SIZE1,SIZE2," +
             "MTL_CHECKER,CALC_BY_CUST_SIZE,SEASON,SHOE_TYPE,SHOE_SEX,DEV_CODE,UPPER_MTL,SOLE_MTL,SOLE_VENDOR,LAST_METHOD,PHOTO_FLAG,SIZE_REGION,NO_MATCHING_LAST," +
             "CUT_SIZE_TYPE,SIZE_TYPE_CHANGE4,SIZE_TYPE_CHANGE1,SIZE_TYPE_CHANGE2,SIZE_TYPE_CHANGE3,SHOELACE_TYPE,INSOLE_TYPE,EMB_VENDOR,HF_VENDOR,COUNTRY,TECH_PERSON," +
             "BASE_CUT_SIZE,PREV_CUST_STYLE,CUST_STYLE)" +
             "values (#{companyId},#{styleNo},#{styleAbbr},#{styleName},#{customNo},#{custNo},#{custBrand},#{lastMold},#{cutTool},#{solePart},#{baseSize},#{sampleDesigner}," +
             "#{prodRemark1},#{prodRemark2},#{prodRemark3},#{prodRemark4},#{prodRemark5},#{sysUser},#{sysDate},#{customName},#{cfmFlag},#{cfmUser},#{cfmDate},#{sizeType}," +
             "#{size1},#{size1},#{mtlChecker},#{calcByCustSize},#{season},#{shoeType},#{shoeSex},#{devCode},#{upperMtl},#{soleMtl},#{soleVendor},#{lastMethod},#{photoFlag},#{sizeRegion}," +
             "#{noMatchingLast},#{cutSizeType},#{sizeTypeChange4},#{sizeTypeChange1},#{sizeTypeChange2},#{sizeTypeChange3},#{shoelaceType},#{insoleType},#{embVendor},#{hfVendor},#{country}," +
             "#{techPerson},#{baseCutSize},#{prevCustStyle},#{custStyle})")
     void addSdStyle(SdStyle sdStyle);

     /**
      * 新增
      * @param sdStyleType
      */
     @Insert("insert into SD_STYLE_TYPE(COMPANY_ID,STYLE_NO,TYPE_NO,LAST_MOLD,CUT_TOOL,SOLE_PART,MIDSOLE,INSOLE,ITEM_NAME,SEQ_NO1,SEQ_NO2,SIZE1,SIZE2)" +
             "values(#{companyId},#{styleNo},#{typeNo},#{lastMold},#{cutTool},#{solePart},#{midsole},#{insole},#{itemName},#{seqNo1},#{seqNo2},#{size1},#{size2})")
     void addSdStyleType(SdStyleType sdStyleType);

     /**
      * 查询型体配色资料
      * @param styleNo
      * @return
      */
     @Select("select * from YF_STYLE_COLOR_DETAIL where STYLE_NO=#{styleNo}")
     List<YfStyleColorDetail> getStyleColorDetail(@Param("styleNo") String styleNo);

     /**
      * 添加型体配色资料
      * @param styleColorPhotoList
      */
     @Insert({
             "<script>",
             "insert into SD_STYLE_COLOR_PHOTO(COMPANY_ID,STYLE_NO,STYLE_COLOR,SEQ_NO,UPPER_COLOR,SOLE_COLOR,UPDATE_TIME,UPDATE_USER,SYS_TIME,SYS_USER,PHOTO_FLAG," +
             "COLOR_CODE,DEV_CODE,PHOTO_PATH,TASK_STATE,ENG_STYLE_COLOR,SHORT_STYLE_COLOR,SEASON) values ",
             "<foreach collection='styleColorPhotoList' item='t' separator=','>",
             "(#{t.companyId},#{t.styleNo},#{t.styleColor},#{t.seqNo},#{t.upperColor},#{t.soleColor},#{t.updateTime},#{t.updateUser},#{t.sysTime},#{t.sysUser}," +
                     "#{t.photoFlag},#{t.colorCode},#{t.devCode},#{t.photoPath},#{t.taskState},#{t.engStyleColor},#{t.shortStyleColor},#{t.season})",
             "</foreach>",
             "</script>",
     })
    void addSdStyleColorPhoto(@Param("styleColorPhotoList") List<SdStyleColorPhoto> styleColorPhotoList);

     /**
      * 查询配码资料
      * @param styleNo
      * @return
      */
     @Select("select * from YF_STYLE_SIZE where STYLE_NO=#{styleNo}")
     List<YfStyleSize> getStyleSizeDetail(@Param("styleNo") String styleNo);

     /**
      * 添加型体配码资料
      * @param sdStyleSizeList
      */
     @Insert({
             "<script>",
             "insert into SD_STYLE_SIZE(STYLE_NO,SEQ_NO,SIZE_NO,CUT_SIZE,LAST_SIZE,SOLE_SIZE,INSOLE_SIZE,COMPANY_ID,MIDSOLE_SIZE,TYPE_NO,LAST_LENGTH,CUST_SIZE)",
             "values ",
             "<foreach collection='sdStyleSizeList' item='t' separator=','>",
             "( #{t.styleNo},#{t.seqNo},#{t.sizeNo},#{t.cutSize},#{t.lastSize},#{t.soleSize},#{t.insoleSize},#{t.companyId},#{t.midsoleSize},#{t.typeNo},#{t.lastLength},#{t.custSize})",
             "</foreach>",
             "</script>"
     })
     void addSdStyleSize(@Param("sdStyleSizeList") List<SdStyleSize> sdStyleSizeList);

    /**
     * 查询型体基本资料
     * @param request
     * @return
     */
    @Select({
            "<script>",
            "select STYLE_NO,STYLE_NAME,SIZE1,SIZE2,BASE_SIZE,SAMPLE_DESIGNER,MTL_CHECKER,SOLE_VENDOR,CUST_NO,CFM_FLAG,DEV_CODE from SD_STYLE",
            "<where>",
            "and COMPANY_ID=#{companyId}",
            "<if test='styleNo != null and !styleNo.isEmpty()'>",
            "and  STYLE_NO LIKE CONCAT('%', #{styleNo}, '%')",
            "</if>",
            "</where>",
            "</script>",
    })
    List<SdStyleDto> getSellStyleList(StyleNoRequest request);

    /**
     * 查询型体配色资料
     * @param styleNo
     * @param companyId
     */
    @Select("select STYLE_NO,COLOR_CODE,STYLE_COLOR,SEQ_NO,DEV_CODE,UPPER_COLOR,PHOTO_PATH,ENG_STYLE_COLOR,SHORT_STYLE_COLOR,TASK_STATE,SEASON from SD_STYLE_COLOR_PHOTO where STYLE_NO=#{styleNo} and COMPANY_ID=#{companyId} order by SEQ_NO")
    List<SdStyleColorDto> getSellStyleColorList(@Param("styleNo") String styleNo, @Param("companyId") String companyId);

    /**
     * 查询型体配码资料
     * @param styleNo
     * @param companyId
     */
    @Select("select SEQ_NO,SIZE_NO,CUT_SIZE,LAST_SIZE,SOLE_SIZE,INSOLE_SIZE,MIDSOLE_SIZE from SD_STYLE_SIZE where STYLE_NO=#{styleNo} and COMPANY_ID=#{companyId} order by SEQ_NO")
    List<YfStyleSizeDto> getSellStyleSizeList(@Param("styleNo") String styleNo, @Param("companyId") String companyId);

    /**
     * 型体制具查询
     * @param styleNo
     * @param companyId
     * @return
     */
    @Select("select TYPE_NO,LAST_MOLD,CUT_TOOL,SOLE_PART,MIDSOLE from SD_STYLE_TYPE where STYLE_NO=#{styleNo} and COMPANY_ID=#{companyId}")
    List<SdStyleTypeDto> getSellStyleTypeToList(@Param("styleNo") String styleNo, @Param("companyId") String companyId);

    /**
     * 查询是否已检核
     * @param styleNo
     * @param companyId
     */
    @Select("select CFM_FLAG from SD_STYLE where STYLE_NO=#{styleNo} and COMPANY_ID=#{companyId} limit 1")
    String getSdStyleCfmFlag(@Param("styleNo") String styleNo, @Param("companyId") String companyId);

    /**
     * 检核
     * @param styleNo
     * @param userName
     * @param companyId
     * @param cfmFlag
     * @param now
     */
    @Update("update SD_STYLE set CFM_FLAG=#{cfmFlag},CFM_DATE=#{now},CFM_USER=#{userName} where STYLE_NO=#{styleNo} and COMPANY_ID=#{companyId}")
    void updateSdStyleCheckOut(@Param("styleNo") String styleNo,
                               @Param("userName") String userName,
                               @Param("companyId") String companyId,
                               @Param("cfmFlag") String cfmFlag,
                               @Param("now") LocalDateTime now);

    /**
     * 查询型体基本资料
     * @param styleNo
     * @param companyId
     * @return
     */
    @Select("select * from SD_STYLE where STYLE_NO=#{styleNo} and COMPANY_ID=#{companyId}")
    SdStyle getSdStyleDetail(@Param("styleNo") String styleNo, @Param("companyId") String companyId);

    /**
     * 查询制具资料
     * @param styleNo
     * @param companyId
     */
    @Select("select * from SD_STYLE_TYPE where STYLE_NO=#{styleNo} and COMPANY_ID=#{companyId}")
    SdStyleType getSdStyleTypeDetail(@Param("styleNo") String styleNo, @Param("companyId") String companyId);

    /**
     * 查询配码资料
     * @param styleNo
     * @param companyId
     */
    @Select("select * from SD_STYLE_SIZE where STYLE_NO=#{styleNo} and COMPANY_ID=#{companyId}")
    List<SdStyleSize> getSdStyleSizeDetail(@Param("styleNo") String styleNo, @Param("companyId") String companyId);

    /**
     * 查询型体配色资料
     * @param styleNo
     * @param companyId
     */
    @Select("select * from SD_STYLE_COLOR_PHOTO where STYLE_NO=#{styleNo} and COMPANY_ID=#{companyId}")
    List<SdStyleColorPhoto> getSdStyleColorPhoto(@Param("styleNo") String styleNo, @Param("companyId") String companyId);

    /**
     * 修改型体基本资料
     * @param sdStyle
     */
    @Update("update SD_STYLE set STYLE_NAME=#{styleName},SIZE1=#{size1},SIZE2=#{size2},BASE_SIZE=#{baseSize},SAMPLE_DESIGNER=#{sampleDesigner},MTL_CHECKER=#{mtlChecker}," +
            "SOLE_VENDOR=#{soleVendor},CUST_NO=#{custNo},SYS_USER=#{sysUser},SYS_DATE=#{sysDate} where STYLE_NO=#{styleNo} and COMPANY_ID=#{companyId}")
    void updateSdStyle(SdStyle sdStyle);

    /**
     * 修改制具资料
     * @param sdStyleType
     */
    @Update("update SD_STYLE_TYPE set LAST_MOLD=#{lastMold},CUT_TOOL=#{cutTool},SOLE_PART=#{solePart},TYPE_NO=#{typeNo} where STYLE_NO=#{styleNo} and COMPANY_ID=#{companyId}")
    void updateSdStyleType(SdStyleType sdStyleType);

    /**
     * 删除型体配色资料
     * @param styleNo
     * @param companyId
     */
    @Delete("delete from SD_STYLE_COLOR_PHOTO where STYLE_NO=#{styleNo} and COMPANY_ID=#{companyId}")
    void delSdStyleColorPhoto(@Param("styleNo") String styleNo, @Param("companyId") String companyId);

    /**
     * 删除型体配码资料
     * @param styleNo
     * @param companyId
     */
    @Delete("delete from SD_STYLE_SIZE where STYLE_NO=#{styleNo} and COMPANY_ID=#{companyId}")
    void delSdStyleSize(@Param("styleNo") String styleNo, @Param("companyId") String companyId);

    /**
     * 查询是否被型体配色建档
     * @param styleNo
     * @param companyId
     * @return
     */
    @Select("select STYLE_NO from SD_BOM_HEAD_NEW2 where STYLE_NO=#{styleNo} and COMPANY_ID=#{companyId} limit 1")
    String getSdBomHeadStyle(@Param("styleNo") String styleNo, @Param("companyId") String companyId);

    /**
     * 删除型体基本资料
     * @param styleNo
     * @param companyId
     */
    @Delete("delete from SD_STYLE where STYLE_NO=#{styleNo} and COMPANY_ID=#{companyId}")
    void delSdStyle(@Param("styleNo") String styleNo, @Param("companyId") String companyId);

    /**
     * 删除型体制具资料
     * @param styleNo
     * @param companyId
     */
    @Delete("delete from SD_STYLE_TYPE where STYLE_NO=#{styleNo} and COMPANY_ID=#{companyId}")
    void delSdStyleType(@Param("styleNo") String styleNo, @Param("companyId") String companyId);

    /**
     * 查询是否被指令引用
     * @param styleNo
     */
    @Select("select count(0) from PC_LOT_HEAD  where STYLE=#{styleNo}")
    Integer getBomInstruct(@Param("styleNo")String styleNo);
}
